<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin std - 通用后台管理模板系统（iframe标准版）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layuiadmin/style/admin.css" media="all">
</head>
<body>
<!--表单入口-->
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
     style="padding: 20px 30px 0 0;">
    <input hidden name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">种类名称</label>
        <div class="layui-input-block">
            <input type="text" name="typeName" lay-verify="title" autocomplete="off" placeholder="请输入种类名称"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">种类描述</label>
        <div class="layui-input-block">
            <input type="text" name="description" lay-verify="title" autocomplete="off" placeholder="请输入你的种类描述"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</div>
<!--富文本编辑器-->
<script src="${pageContext.request.contextPath}/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${pageContext.request.contextPath}/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;
        //监听提交
        form.on('submit(submit)', function (data) {
            let field = data.field; //获取提交的字段
            let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //使用ajax进行数据传递
            $.post({
                url: "${pageContext.request.contextPath}/admin/type?method=update",
                data: {
                    data: JSON.stringify(field)
                }
                ,
                success: function (data) {
                    if (data === "true") {
                        parent.layui.table.reload('type'); //重载表格
                        parent.layer.close(index); //再执行关闭
                    } else {
                        layer.alert("修改失败", function () {
                            parent.layui.table.reload('type'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        })
                    }
                }
            })

        });
    })
</script>
</body>
</html>
